<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/3/8
  Time: 17:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@include file="../../../base.jsp" %>
<div class="modal-header">
    <!--右边内容显示 功能显示-->

    <form class="form-horizontal text-left" id="addBannerForm">
        <h3>新增Banner</h3>
    </form>
</div>
<br>
<h1 class="text-primary">Banner列表</h1>
<table class="table table-hover">
    <thead>
    <tr>
        <th>#</th>
        <th>状态</th>
        <th>预览图片</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${banners}" var="sysFile" varStatus="vs">
        <tr class="
                <c:if test="${sysFile.status == 50}">
                    success
                </c:if>
                <c:if test="${sysFile.status == 0}">
                    danger
                </c:if>
                ">
            <th scope="row">${vs.count}</th>
            <td>
                <c:if test="${sysFile.status == 0}">
                    <strong style="color: black">[未发布]</strong>
                    <button type="button" class="btn btn-primary btn-sm"
                            onclick="banner.changeBannerStatus('${sysFile.fileId}',50)">
                        一键发布
                    </button>
                </c:if>
                <c:if test="${sysFile.status == 50}">
                    <strong style="color: green">[已发布]</strong>
                    <button type="button" class="btn btn-danger btn-sm"
                            onclick="banner.changeBannerStatus('${sysFile.fileId}',0)">
                        一键取消
                    </button>
                </c:if>
            </td>
            <td>
                <img src="${fileBaseUrl}/sysfile/download?sysFile.fileId=${sysFile.fileId}"
                     alt=" 加载失败" class="img-thumbnail">
            </td>

        </tr>
    </c:forEach>

    </tbody>
</table>
<script>
    $(function () {
        JWB.http.uploadImgPage(ModuleCode.BANNER, ModuleCode.BANNER, function (res) {
            alert(res.msg);
            if(res.code == 0) {
                index_js.reloadRightPage();
            }
        }, $("#addBannerForm"));
    });

    var banner = {
        changeBannerStatus: function (fileId, status) {
            $.ajax({
                url: base.basePath + "sysfile/updatestatus?fileId=" + fileId + "&status=" + status,
                success: function (res) {
                    alert(res.msg);
                    if(res.code == 0) {
                        index_js.reloadRightPage();
                    }
                },
                error: function (jXHR, textStatus, errorThrown) {
                    JWB.http.errorHandle(jXHR, textStatus, errorThrown)
                }
            });
        }
    }
</script>